package com.luoling.oa.oaSync.controller;

import com.luoling.oa.oaSync.domian.Response;
import com.luoling.oa.oaSync.domian.Request;
import com.luoling.oa.oaSync.service.OaSyncService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.HashMap;

/**
 * Description:
 * Copyright:   Copyright (c)2024
 * Company:
 *
 * @author: 张李鑫
 * @version: 1.0
 * Create at:   2024-12-17 14:45:26
 * <p>
 * Modification History:
 * Date         Author      Version     Description
 * ------------------------------------------------------------------
 * 2024-12-17     张李鑫                     1.0         1.0 Version
 */

@RestController
@RequestMapping("/oa")
public class OaController {
    private static final Logger log = LoggerFactory.getLogger(OaController.class);

    @Autowired
    private OaSyncService oaSyncService;


    @RequestMapping("/sync")
    public void department(@RequestBody Request request, HttpServletResponse response) throws IOException {
        log.info("request:{}",request.toString());
        String res;
        try {
            oaSyncService.sync(request.getData());
            res = Response.success();
        } catch (Exception e) {
            res = Response.error();
            log.error("sync err :{}", e.getMessage());
        }
        PrintWriter writer = response.getWriter();
        writer.println(res);
        writer.flush();
        writer.close();
    }

    @RequestMapping("/v1/sync")
    public void departmentV1(
            @RequestBody HashMap<String,String>request
            ) throws IOException {
        log.info("request:{}",request.toString());

    }
}
